package com.mall.service.marketing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.model.domain.SmsHomeRecommendProduct;
import com.mall.model.domain.SmsHomeRecommendSubject;
import com.mall.model.vo.PageResult;
import com.mall.service.marketing.mapper.SmsHomeRecommendSubjectMapper;
import com.mall.service.marketing.service.SmsHomeRecommendSubjectService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SmsHomeRecommendSubjectServiceImpl extends ServiceImpl<SmsHomeRecommendSubjectMapper, SmsHomeRecommendSubject> implements SmsHomeRecommendSubjectService {

    @Autowired
    private SmsHomeRecommendSubjectMapper smsHomeRecommendSubjectMapper;

    @Override
    public PageResult findList(String subjectName, Integer recommendStatus, Integer pageNum, Integer pageSize) {
        Page<SmsHomeRecommendSubject> page = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<SmsHomeRecommendSubject> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(subjectName)){
            queryWrapper.like(SmsHomeRecommendSubject::getSubjectName,subjectName);
        }
        if (recommendStatus != null){
            queryWrapper.eq(SmsHomeRecommendSubject::getRecommendStatus,recommendStatus);
        }
        Page<SmsHomeRecommendSubject> shnpPage = smsHomeRecommendSubjectMapper.selectPage(page, queryWrapper);
        return new PageResult(pageNum,pageSize, (int) shnpPage.getTotal(),shnpPage.getRecords());
    }
}
